package com.taptech.doufu.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.ui.activity.NewOthersPersonalActivity;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.bean.personalcenter.SweepFlowerBean;
import com.taptech.doufu.services.personalcenter.AccountService;
import com.taptech.doufu.ui.activity.UserDetailActivity;
import com.taptech.doufu.ui.view.UserGradeView;
import com.taptech.doufu.util.ImageManager;
import com.taptech.doufu.ui.view.RoundImageView;

/**
 * 
 */
public class FlowerRankAapater extends BaseListAdapter {


	public FlowerRankAapater(Activity activity) {
	}

	@Override
	public View getView(int position, View convertView, final ViewGroup parent) {
		ViewHolder holder ;
		if (convertView == null) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(
					R.layout.item_flower_all_rank, null);
			holder = new ViewHolder();
			holder.layUserGrade = convertView.findViewById(R.id.layUserGrade);
			holder.userLabel = (TextView) convertView
					.findViewById(R.id.user_label);
			holder.userHeader = (RoundImageView) convertView
					.findViewById(R.id.user_header_icon);
			holder.flowerCount = (TextView) convertView.findViewById(R.id.flower_count_tv);
			convertView.setTag(holder);
		}
		initData(convertView, position);
		return convertView;
	}

	private void initData(final View convertView, final int position) {
		try {
			final SweepFlowerBean info = (SweepFlowerBean) getItem(position);
			if (info == null)
				return;
			final ViewHolder holder = (ViewHolder) convertView.getTag();
			holder.userHeader
					.setImageResource(R.drawable.default_user_portrait);
			convertView.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (!info.getUid().equals(
							AccountService.getInstance().getUserUid())) {
						UserDetailActivity.Companion.startActivity(v.getContext(),info.getUid());
					}
					

				}
			});
			

				ImageManager.displayImage(holder.userHeader, info.getUser().getIcon());
//			}
			holder.layUserGrade.setData(info.getUser(),false);
			holder.userLabel.setText("");
			holder.flowerCount.setText(info.getNum());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected class ViewHolder {
		RoundImageView userHeader;
		TextView  userLabel, flowerCount;
		UserGradeView layUserGrade;
	}


}
